<template>
  <div>
    <div class="gva-search-box">
      <el-form ref="elSearchFormRef" :inline="true" :model="searchInfo" class="demo-form-inline" :rules="searchRule" @keyup.enter="onSubmit">
      <el-form-item label="创建日期" prop="createdAt">
      <template #label>
        <span>
          创建日期
          <el-tooltip content="搜索范围是开始日期（包含）至结束日期（不包含）">
            <el-icon><QuestionFilled /></el-icon>
          </el-tooltip>
        </span>
      </template>
      <el-date-picker v-model="searchInfo.startCreatedAt" type="datetime" placeholder="开始日期" :disabled-date="time=> searchInfo.endCreatedAt ? time.getTime() > searchInfo.endCreatedAt.getTime() : false"></el-date-picker>
       —
      <el-date-picker v-model="searchInfo.endCreatedAt" type="datetime" placeholder="结束日期" :disabled-date="time=> searchInfo.startCreatedAt ? time.getTime() < searchInfo.startCreatedAt.getTime() : false"></el-date-picker>
      </el-form-item>
        <el-form-item label="影片名" prop="name">
         <el-input v-model="searchInfo.name" placeholder="搜索条件" />

        </el-form-item>
           <el-form-item label="是否完结" prop="fullFlag">
            <el-select v-model="searchInfo.fullFlag" clearable placeholder="请选择" @clear="()=>{searchInfo.fullFlag=undefined}">
              <el-option v-for="(item,key) in finishStatusOptions" :key="key" :label="item.label" :value="item.value" />
            </el-select>
            </el-form-item>
           <el-form-item label="状态" prop="status">
            <el-select v-model="searchInfo.status" clearable placeholder="请选择" @clear="()=>{searchInfo.status=undefined}">
              <el-option v-for="(item,key) in shelvesOptions" :key="key" :label="item.label" :value="item.value" />
            </el-select>
            </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="search" @click="onSubmit">查询</el-button>
          <el-button icon="refresh" @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="gva-table-box">
        <div class="gva-btn-list">
          <!-- //   btnAuth为权限组件固定写法 .movieAdd  movieAdd为菜单管理中创建的按钮名称 配置过后即可实现对按钮的控制 -->
            <el-button type="primary" icon="plus" @click="openDialog" v-auth="btnAuth.movieAdd">新增</el-button>
            <el-popover v-model:visible="deleteVisible" :disabled="!multipleSelection.length" placement="top" width="160">
            <p>确定要删除吗？</p>
            <div style="text-align: right; margin-top: 8px;">
                <el-button type="primary" link @click="deleteVisible = false">取消</el-button>
                <el-button type="primary" @click="onDelete">确定</el-button>
            </div>
            <template #reference>
                <el-button v-auth="btnAuth.movieDel" icon="delete" style="margin-left: 10px;" :disabled="!multipleSelection.length" @click="deleteVisible = true" >删除</el-button>
            </template>
            </el-popover>
        </div>
        <el-table
        ref="multipleTable"
        style="width: 100%"
        tooltip-effect="dark"
        :data="tableData"
        row-key="ID"
        @selection-change="handleSelectionChange"
        >
        <el-table-column type="selection" width="55" />
        <el-table-column align="left" label="ID" prop="ID" width="120" />
        <el-table-column align="left" label="影片名" prop="name" width="120" />
          <el-table-column label="竖版封面" width="150">
              <template #default="scope">
                <el-image style="width: 100px; height: 140px" :src="getUrl(scope.row.imgFullUrl)" fit="cover"/>
              </template>
          </el-table-column>
          <!-- <el-table-column label="横版封面" width="150">
              <template #default="scope">
                <el-image style="width: 140px; height: 100px" :src="getUrl(scope.row.bannerFullUrl)" fit="cover"/>
              </template>
          </el-table-column> -->
        <!-- <el-table-column align="left" label="作者" prop="author" width="120" /> -->
        <el-table-column align="left" label="总集数" prop="totalCnt" width="120" />
        <el-table-column align="left" label="最大免费集数" prop="maxFreeCnt" width="80" />
        <el-table-column align="left" label="每单集价格" prop="price" width="80" />
        <el-table-column align="left" label="连载状态" prop="fullFlag" width="120">
            <template #default="scope">
            {{ filterDict(scope.row.fullFlag,finishStatusOptions) }}
            </template>
        </el-table-column>
        <!-- <el-table-column align="left" label="合作方id" prop="cpId" width="120" /> -->
         <!-- <el-table-column align="left" label="CP更新日期" width="180">
            <template #default="scope">{{ formatDate(scope.row.cpUpdateTime) }}</template>
         </el-table-column> -->
        <!-- <el-table-column align="left" label="主角名" prop="protagonist" width="120" />
        <el-table-column align="left" label="标签" prop="tag" width="120" />
        <el-table-column align="left" label="简介" prop="intro" width="120" />
        <el-table-column align="left" label="推荐语" prop="recommend" width="120" />
        <el-table-column align="left" label="备注" prop="remarks" width="120" /> -->
        <el-table-column align="left" label="上架状态" prop="status" width="120">
            <template #default="scope">
            {{ filterDict(scope.row.status,shelvesOptions) }}
            </template>
        </el-table-column>
        <el-table-column align="left" label="第一集编号" prop="firstSid" width="120" />
        <!-- <el-table-column align="left" label="最新集信息" prop="latestEpisode" width="120" /> -->
        <!-- <el-table-column align="left" label="创建人" prop="createUid" width="120" />
         <el-table-column align="left" label="创建时间" width="180">
            <template #default="scope">{{ formatDate(scope.row.createTime) }}</template>
         </el-table-column>
        <el-table-column align="left" label="更新人" prop="updateUid" width="120" />
         <el-table-column align="left" label="更新时间" width="180">
            <template #default="scope">{{ formatDate(scope.row.updateTime) }}</template>
         </el-table-column> -->
         <el-table-column align="left" label="备注" prop="remarks" width="130"  v-auth="btnAuth.remarksShow" />
        <el-table-column align="left" label="操作" fixed="right" width="140">
            <template #default="scope">
            <el-button v-auth="btnAuth.referralAddByMovie" type="primary" link icon="promotion" class="table-button" @click="referralAddByMovie(scope.row)">生成推广链接</el-button>
            <el-button v-auth="btnAuth.movieDetail" type="primary" icon="InfoFilled" link class="table-button" @click="getDetails(scope.row)">查看详情</el-button>

            <el-button v-auth="btnAuth.movieEdit" type="primary" link icon="edit" class="table-button" @click="updateMovieAutoFunc(scope.row)">变更</el-button>
            
            <el-button v-auth="btnAuth.movieDel" type="primary" link icon="delete" @click="deleteRow(scope.row)">删除</el-button>
            </template>
        </el-table-column>
        <el-table-column align="left" label="媒资操作" fixed="right" width="140">
            <template #default="scope">
            <el-button v-auth="btnAuth.episodeList" type="primary" link icon="edit" class="table-button" @click="episodeListByMovie(scope.row)">剧集管理</el-button>
            <el-button v-auth="btnAuth.movieAuditListTt" type="primary" link icon="edit" class="table-button" @click="moviesAuditTTListByMovie(scope.row)">抖音媒资</el-button>
            <el-button v-auth="btnAuth.movieAuditListWx" type="primary" link icon="edit" class="table-button" @click="moviesAuditWXSync(scope.row)">微信媒资同步</el-button>
            </template>
        </el-table-column>
        </el-table>
        <div class="gva-pagination">
            <el-pagination
            layout="total, sizes, prev, pager, next, jumper"
            :current-page="page"
            :page-size="pageSize"
            :page-sizes="[10, 30, 50, 100]"
            :total="total"
            @current-change="handleCurrentChange"
            @size-change="handleSizeChange"
            />
        </div>
    </div>
    <el-dialog v-model="dialogFormVisible" :before-close="closeDialog" :title="type==='create'?'添加':'修改'" destroy-on-close>
      <el-scrollbar height="500px">
          <el-form :model="formData" label-position="right" ref="elFormRef" :rules="rule" label-width="140px" class="grid grid-cols-2">
            <el-form-item label="影片名:"  prop="name" >
              <el-input v-model="formData.name" :clearable="true"  placeholder="请输入影片名" />
            </el-form-item>
            <el-form-item label="总集数:"  prop="totalCnt" >
              <el-input v-model.number="formData.totalCnt" :clearable="true" placeholder="请输入总集数" />
            </el-form-item>
            <el-form-item label="最大免费集数:"  prop="maxFreeCnt" >
              <el-input v-model.number="formData.maxFreeCnt" :clearable="true" placeholder="请输入最大免费集数" />
            </el-form-item>
            <el-form-item label="每单集价格:"  prop="price" >
              <el-input v-model.number="formData.price" :clearable="true" placeholder="请输入每单集价格" />
            </el-form-item>
            <el-form-item label="竖版封面:"  prop="imgUrl" >
                <SelectImage
                 v-model="formData.imgUrl"
                 file-type="image"
                 :movie-id="formData.ID"
                />
            </el-form-item>
            <el-form-item label="横版封面:"  prop="bannerImgUrl" >
                <SelectImage
                 v-model="formData.bannerImgUrl"
                 file-type="image"
                 :movie-id="formData.ID"
                />
            </el-form-item>
            <el-form-item label="作者:"  prop="author" >
              <el-input v-model="formData.author" :clearable="true"  placeholder="请输入作者" />
            </el-form-item>
            <el-form-item label="是否完结:"  prop="fullFlag" >
              <el-select v-model="formData.fullFlag" placeholder="请选择" style="width:100%" :clearable="true" >
                <el-option v-for="(item,key) in finishStatusOptions" :key="key" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="上架状态:"  prop="status" >
              <el-select v-model="formData.status" placeholder="请选择状态" style="width:100%" :clearable="true" >
                <el-option v-for="(item,key) in shelvesOptions" :key="key" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="合作方id:"  prop="cpId" >
              <el-input v-model.number="formData.cpId" :clearable="true" placeholder="请输入合作方id" />
            </el-form-item>
            <el-form-item label="CP更新日期:"  prop="cpUpdateTime" >
              <el-date-picker v-model="formData.cpUpdateTime" type="date" style="width:100%" placeholder="选择日期" :clearable="true"  />
            </el-form-item> -->
            <el-form-item label="主角名:"  prop="protagonist" >
              <el-input v-model="formData.protagonist" :clearable="true"  placeholder="请输入主角名" />
            </el-form-item>
            <el-form-item label="备注:"  prop="remarks" >
              <el-input v-model="formData.remarks" :clearable="true"  placeholder="请输入备注" />
            </el-form-item>
            <el-form-item label="标签:"  prop="tag" >
              <el-input v-model="formData.tag" :clearable="true"  placeholder="请输入标签" />
            </el-form-item>
            <el-form-item label="推荐语:"  prop="recommend" >
              <el-input v-model="formData.recommend" :clearable="true"  placeholder="请输入推荐语(12字以内)" type="textarea" :rows="4"  maxlength="12"/>
            </el-form-item>
            <el-form-item label="简介:"  prop="intro" >
              <el-input v-model="formData.intro" :clearable="true"  :rows="4"  placeholder="请输入简介(200字以内)" type="textarea" maxlength="200"/>
            </el-form-item>
          </el-form>
      </el-scrollbar>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeDialog">取 消</el-button>
          <el-button type="primary" @click="enterDialog">确 定</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog v-model="detailShow" style="width: 800px" lock-scroll :before-close="closeDetailShow" title="查看详情" destroy-on-close>
      <el-scrollbar height="550px">
        <el-descriptions column="1" border>
                <el-descriptions-item label="影片名">
                        {{ formData.name }}
                </el-descriptions-item>
                <el-descriptions-item label="竖版封面内容md5">
                        <el-image style="width: 50px; height: 50px" :preview-src-list="ReturnArrImg(formData.imgUrl)" :src="getUrl(formData.imgUrl)" fit="cover" />
                </el-descriptions-item>
                <el-descriptions-item label="横版封面内容md5">
                        <el-image style="width: 50px; height: 50px" :preview-src-list="ReturnArrImg(formData.bannerImgUrl)" :src="getUrl(formData.bannerImgUrl)" fit="cover" />
                </el-descriptions-item>
                <el-descriptions-item label="作者">
                        {{ formData.author }}
                </el-descriptions-item>
                <el-descriptions-item label="总集数">
                        {{ formData.totalCnt }}
                </el-descriptions-item>
                <el-descriptions-item label="最大免费集数">
                        {{ formData.maxFreeCnt }}
                </el-descriptions-item>
                <el-descriptions-item label="每单集价格">
                        {{ formData.price }}
                </el-descriptions-item>
                <el-descriptions-item label="是否完结：1、完结，2、连载">
                        {{ filterDict(formData.fullFlag,finishStatusOptions) }}
                </el-descriptions-item>
                <el-descriptions-item label="合作方id">
                        {{ formData.cpId }}
                </el-descriptions-item>
                <el-descriptions-item label="CP更新日期">
                      {{ formatDate(formData.cpUpdateTime) }}
                </el-descriptions-item>
                <el-descriptions-item label="主角名">
                        {{ formData.protagonist }}
                </el-descriptions-item>
                <el-descriptions-item label="标签">
                        {{ formData.tag }}
                </el-descriptions-item>
                <el-descriptions-item label="简介">
                        {{ formData.intro }}
                </el-descriptions-item>
                <el-descriptions-item label="推荐语">
                        {{ formData.recommend }}
                </el-descriptions-item>
                <el-descriptions-item label="备注">
                        {{ formData.remarks }}
                </el-descriptions-item>
                <el-descriptions-item label="状态:1、上架，2、下架">
                        {{ filterDict(formData.status,shelvesOptions) }}
                </el-descriptions-item>
                <el-descriptions-item label="第一集id">
                        {{ formData.firstSid }}
                </el-descriptions-item>
                <el-descriptions-item label="最新集信息id<>:name<>:ctime">
                        {{ formData.latestEpisode }}
                </el-descriptions-item>
                <el-descriptions-item label="创建人">
                        {{ formData.createUid }}
                </el-descriptions-item>
                <el-descriptions-item label="创建时间">
                      {{ formatDate(formData.createTime) }}
                </el-descriptions-item>
                <el-descriptions-item label="更新人">
                        {{ formData.updateUid }}
                </el-descriptions-item>
                <el-descriptions-item label="更新时间">
                      {{ formatDate(formData.updateTime) }}
                </el-descriptions-item>
        </el-descriptions>
      </el-scrollbar>
    </el-dialog>

    <el-drawer
      v-if="drawerReferralAddFormVisible"
      v-model="drawerReferralAddFormVisible"
      custom-class="auth-drawer"
      :with-header="false"
      size="40%"
      title="生成推广"
    >
      <el-tabs
        :before-leave="autoEnter"
        type="border-card"
      >
        <el-tab-pane label="生成推广链接">
          <ReferralForm
            ref="referralForm"
            :row="formData"
            @enterReferralAdd="enterReferralAdd"
          />
        </el-tab-pane>
      </el-tabs>
    </el-drawer>

    <el-drawer
      v-if="drawerEpisodeListVisible"
      v-model="drawerEpisodeListVisible"
      custom-class="auth-drawer"
      :with-header="false"
      size="80%"
      title="剧集管理"
    >
      <el-tabs
        :before-leave="autoEnter"
        type="border-card"
      >
        <el-tab-pane label="剧集管理">
          <EpisodeList
            ref="episodeList"
            :row="formData"
          />
        </el-tab-pane>
      </el-tabs>
    </el-drawer>
    <el-drawer
      v-if="drawerMoviesAuditTTListVisible"
      v-model="drawerMoviesAuditTTListVisible"
      custom-class="auth-drawer"
      :with-header="false"
      size="80%"
      title="抖音提审管理"
    >
      <el-tabs
        :before-leave="autoEnter"
        type="border-card"
      >
        <el-tab-pane label="抖音提审管理">
          <MoviesAuditTtList
            ref="moviesAuditTtList"
            :row="formData"
          />
        </el-tab-pane>
      </el-tabs>
    </el-drawer>
  </div>
</template>

<script setup>
import {
  createMovieAuto,
  deleteMovieAuto,
  deleteMovieAutoByIds,
  updateMovieAuto,
  findMovieAuto,
  getMovieAutoList
} from '@/api/movieAuto'
import {
  playLetAlbumOnlineSync,
} from '@/api/moviesAuditTt'

import { getUrl } from '@/utils/image'
// 图片选择组件
import SelectImage from '@/components/selectImage/selectImage.vue'

// 生成推广链接组件
import ReferralForm from '@/view/tReferral/tReferralForm.vue'

// 剧集管理
import EpisodeList from '@/view/episode/episode.vue'

// 抖音提审管理
import MoviesAuditTtList from '@/view/moviesAuditTt/moviesAuditTt.vue'


// 全量引入格式化工具 请按需保留
import { getDictFunc, formatDate, formatBoolean, filterDict, ReturnArrImg, onDownloadFile } from '@/utils/format'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive } from 'vue'

//引用菜单按钮权限组件
import { useBtnAuth } from '@/utils/btnAuth'
    const btnAuth = useBtnAuth()

defineOptions({
    name: 'MovieAuto'
})

// 自动化生成的字典（可能为空）以及字段
const finishStatusOptions = ref([])
const shelvesOptions = ref([])
const formData = ref({
        name: '',
        imgUrl: "",
        bannerImgUrl: "",
        author: '',
        totalCnt: '',
        maxFreeCnt: '',
        price: '',
        fullFlag: 1,
        cpId: 0,
        cpUpdateTime: new Date(),
        protagonist: '',
        tag: '',
        intro: '',
        recommend: '',
        remarks: '',
        status: 2,
        firstSid: 0,
        latestEpisode: '',
        createUid: 0,
        createTime: new Date(),
        updateUid: 0,
        updateTime: new Date(),
        })

const moviePriceMinMax =  (rule, value, callback) => {
  if(value>350|| value<10) {
    callback('超出限制')
  } else {
    callback()
  }
}
const movieTotalCntMinMax =  (rule, value, callback) => {
  if(value>500|| value<=0) {
    callback('超出限制')
  } else {
    callback()
  }
}

// 验证规则
const rule = reactive({
               name : [{
                   required: true,
                   message: '',
                   trigger: ['input','blur'],
               },
               {
                   whitespace: true,
                   message: '不能只输入空格',
                   trigger: ['input', 'blur'],
              }
              ],
               imgUrl : [{
                   required: false,
                   message: '',
                   trigger: ['input','blur'],
               },
              ],
               maxFreeCnt : [{
                   required: true,
                   message: '',
                   trigger: ['input','blur'],
               },
              ],
               price : [{ 
                  validator: moviePriceMinMax, 
                  message: '单集价格范围10-350',
                  trigger: 'blur'
                },
                {type: 'number', message: '请输入数字', trigger: 'blur'}
              ],
              totalCnt : [{
                  validator: movieTotalCntMinMax, 
                    message: '总集数范围1~500',
                    trigger: 'blur'
               },
               {type: 'number', message: '请输入数字', trigger: 'blur'}
              ],
              fullFlag : [{
                   required: true,
                   message: '请选择连载状态',
                   trigger: ['input','blur'],
               },
              ],
              status : [{
                   required: true,
                   message: '请选择上下架状态',
                   trigger: ['input','blur'],
               },
              ],
})

const searchRule = reactive({
  createdAt: [
    { validator: (rule, value, callback) => {
      if (searchInfo.value.startCreatedAt && !searchInfo.value.endCreatedAt) {
        callback(new Error('请填写结束日期'))
      } else if (!searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt) {
        callback(new Error('请填写开始日期'))
      } else if (searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt && (searchInfo.value.startCreatedAt.getTime() === searchInfo.value.endCreatedAt.getTime() || searchInfo.value.startCreatedAt.getTime() > searchInfo.value.endCreatedAt.getTime())) {
        callback(new Error('开始日期应当早于结束日期'))
      } else {
        callback()
      }
    }, trigger: 'change' }
  ],
})

const elFormRef = ref()
const elSearchFormRef = ref()

// =========== 表格控制部分 ===========
const page = ref(1)
const total = ref(0)
const pageSize = ref(10)
const tableData = ref([])
const searchInfo = ref({})

// 重置
const onReset = () => {
  searchInfo.value = {}
  getTableData()
}

// 搜索
const onSubmit = () => {
  elSearchFormRef.value?.validate(async(valid) => {
    if (!valid) return
    page.value = 1
    pageSize.value = 10
    getTableData()
  })
}

// 分页
const handleSizeChange = (val) => {
  pageSize.value = val
  getTableData()
}

// 修改页面容量
const handleCurrentChange = (val) => {
  page.value = val
  getTableData()
}

// 查询
const getTableData = async() => {
  const table = await getMovieAutoList({ page: page.value, pageSize: pageSize.value, ...searchInfo.value })
  if (table.code === 0) {
    tableData.value = table.data.list
    total.value = table.data.total
    page.value = table.data.page
    pageSize.value = table.data.pageSize
  }
}

getTableData()

// ============== 表格控制部分结束 ===============

// 获取需要的字典 可能为空 按需保留
const setOptions = async () =>{
    finishStatusOptions.value = await getDictFunc('finishStatus')
    shelvesOptions.value = await getDictFunc('shelves')
}

// 获取需要的字典 可能为空 按需保留
setOptions()


// 多选数据
const multipleSelection = ref([])
// 多选
const handleSelectionChange = (val) => {
    multipleSelection.value = val
}

// 删除行
const deleteRow = (row) => {
    ElMessageBox.confirm('确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
            deleteMovieAutoFunc(row)
        })
    }


// 批量删除控制标记
const deleteVisible = ref(false)

// 多选删除
const onDelete = async() => {
      const ids = []
      if (multipleSelection.value.length === 0) {
        ElMessage({
          type: 'warning',
          message: '请选择要删除的数据'
        })
        return
      }
      multipleSelection.value &&
        multipleSelection.value.map(item => {
          ids.push(item.ID)
        })
      const res = await deleteMovieAutoByIds({ ids })
      if (res.code === 0) {
        ElMessage({
          type: 'success',
          message: '删除成功'
        })
        if (tableData.value.length === ids.length && page.value > 1) {
          page.value--
        }
        deleteVisible.value = false
        getTableData()
      }
    }

// 行为控制标记（弹窗内部需要增还是改）
const type = ref('')

// 更新行
const updateMovieAutoFunc = async(row) => {
    const res = await findMovieAuto({ ID: row.ID })
    console.log(res)
    type.value = 'update'
    if (res.code === 0) {
        formData.value = res.data.removie
        dialogFormVisible.value = true
    }
}


// 删除行
const deleteMovieAutoFunc = async (row) => {
    const res = await deleteMovieAuto({ ID: row.ID })
    if (res.code === 0) {
        ElMessage({
                type: 'success',
                message: '删除成功'
            })
            if (tableData.value.length === 1 && page.value > 1) {
            page.value--
        }
        getTableData()
    }
}

// 新建推广链接行
const referralAddByMovie = async(row) => {
    // const res = await findMovieAuto({ ID: row.ID })
    // if (res.code === 0) {
        formData.value = row
        drawerReferralAddFormVisible.value = true
    // }
}

// 生成推广链接抽屉控制标记
const drawerReferralAddFormVisible = ref(false)


// 弹窗控制标记
const dialogFormVisible = ref(false)


// 查看详情控制标记
const detailShow = ref(false)


// 打开详情弹窗
const openDetailShow = () => {
  detailShow.value = true
}


// 打开详情
const getDetails = async (row) => {
  // 打开弹窗
  const res = await findMovieAuto({ ID: row.ID })
  if (res.code === 0) {
    formData.value = res.data.removie
    openDetailShow()
  }
}


// 关闭详情弹窗
const closeDetailShow = () => {
  detailShow.value = false
  formData.value = {
          name: '',
          author: '',
          totalCnt: 0,
          maxFreeCnt: 0,
          price: 0,
          fullFlag: undefined,
          cpId: 0,
          cpUpdateTime: new Date(),
          protagonist: '',
          tag: '',
          intro: '',
          recommend: '',
          remarks: '',
          status: undefined,
          firstSid: 0,
          latestEpisode: '',
          createUid: 0,
          createTime: new Date(),
          updateUid: 0,
          updateTime: new Date(),
          }
}


// 打开弹窗
const openDialog = () => {
    type.value = 'create'
    dialogFormVisible.value = true
}

// 关闭弹窗
const closeDialog = () => {
    dialogFormVisible.value = false
    formData.value = {
        name: '',
        author: '',
        totalCnt: 0,
        maxFreeCnt: 0,
        price: 0,
        fullFlag: undefined,
        cpId: 0,
        cpUpdateTime: new Date(),
        protagonist: '',
        tag: '',
        intro: '',
        recommend: '',
        remarks: '',
        status: undefined,
        firstSid: 0,
        latestEpisode: '',
        createUid: 0,
        createTime: new Date(),
        updateUid: 0,
        updateTime: new Date(),
        }
}
// 弹窗确定
const enterDialog = async () => {
     elFormRef.value?.validate( async (valid) => {
             if (!valid) return
              let res
              switch (type.value) {
                case 'create':
                  res = await createMovieAuto(formData.value)
                  break
                case 'update':
                  res = await updateMovieAuto(formData.value)
                  break
                default:
                  res = await createMovieAuto(formData.value)
                  break
              }
              if (res.code === 0) {
                ElMessage({
                  type: 'success',
                  message: '创建/更改成功'
                })
                closeDialog()
                getTableData()
              }
      })
}
// 子组件控制关闭
const enterReferralAdd = (close) => {
    drawerReferralAddFormVisible.value = close
}

// 打开剧集管理抽屉
const episodeListByMovie = async(row) => {
    // const res = await findMovieAuto({ ID: row.ID })
    // if (res.code === 0) {
        formData.value = row
        drawerEpisodeListVisible.value = true
    // }
}

// 打开剧集管理抽屉
const drawerEpisodeListVisible = ref(false)

// 抖音审核管理抽屉
const moviesAuditTTListByMovie = async(row) => {
    // const res = await findMovieAuto({ ID: row.ID })
    // if (res.code === 0) {
        formData.value = row
        drawerMoviesAuditTTListVisible.value = true
    // }
}

// 关闭抖音审核管理抽屉
const drawerMoviesAuditTTListVisible = ref(false)


// 同步微信媒资-操作
const moviesAuditWXSync = (row) => {
    ElMessageBox.confirm('确定要同步结果吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
      playLetAlbumOnlineFunc(row)
        })
    }
// 
const playLetAlbumOnlineFunc = async (row) => {
    const res = await playLetAlbumOnlineSync({ movieId: row.ID })
    if (res.code === 0) {
        ElMessage({
                type: 'success',
                message: '操作成功'
            })
        getTableData()
    }
}
</script>

<style>

</style>
